package com.smzd.projforge.domain;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.smzd.core.annotations.ModuleGroup;
import com.smzd.core.domain.BaseScopeEntity;

@ModuleGroup(value = "projforge", moduleName="class", moduleNames = "classes")
public class DynaClass extends BaseScopeEntity<Project> {
	private static final long serialVersionUID = 3620099224598855732L;
	public static final int SCOPE_GLOBAL = 0;
	public static final int SCOPE_MEETING = 1;
	public static final int SCOPE_GROUP = 2;
	public static final int SCOPE_USER = 3;
	//类名。没有的话自动命名规则为C{id}
	private String className;
	
	//资源名称，也是访问入口uri的标识符
	private String entryName;
	private String entryNames;
	//数据库表名称
	private String tableName;
	//数据库表名简称
	private String tableAlias;

	// 所有者层级。目前支持全局数据(0)、会务数据(1)、组数据(2)、用户数据(3)等作用范围。值参见常量SCOPE_{LEVEL}系列
	private int ownerLevel;
	
	//一对多关系的主方类。如果没有，则表示该类不是某类的从类。
	private DynaClass scopeClass;

	//-------------关系--------------------
	//多对多关系记录
	private List<MTMRelation> mtmRelations = new ArrayList<>();

	// 类的属性的集合
	private List<DynaAttribute> dynaAttributes;
	
	private Suit suit;
	
	private transient Boolean checked;
	
	
	public DynaClass(){}
	public DynaClass(int id){
		setId(id);
	}
	
//	public void addMTMRelation(DynaClass master){
//		mtmRelations.add(new MTMRelation(master, this));
//	}
	public void addMTMRelation(MTMRelation relation){
		mtmRelations.add(relation);
	}
	
	public String getModuleName(){
		if(!StringUtils.isEmpty(this.getEntryName())){
			return this.getEntryName().toLowerCase();
		}
		if(!StringUtils.isEmpty(this.getClassName())){
			return this.getClassName().toLowerCase();
		}
		return "c"+this.getId();
	}
	
	public String getModuleNames(){
		if(!StringUtils.isEmpty(this.getEntryNames())){
			return this.getEntryNames().toLowerCase();
		}
		return getModuleName()+"s";
	}
	public String getFullEntry(){
		String fullEntry = scope.getEntry();
		if(StringUtils.isEmpty(fullEntry)){
			fullEntry = "";
		}
		fullEntry += "/"+getModuleNames();
		return fullEntry;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getEntryName() {
		return entryName;
	}

	public void setEntryName(String entryName) {
		this.entryName = entryName;
	}

	public String getEntryNames() {
		return entryNames;
	}

	public void setEntryNames(String entryNames) {
		this.entryNames = entryNames;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public int getOwnerLevel() {
		return ownerLevel;
	}

	public void setOwnerLevel(int ownerLevel) {
		this.ownerLevel = ownerLevel;
	}

	public DynaClass getScopeClass() {
		return scopeClass;
	}

	public void setScopeClass(DynaClass scopeClass) {
		this.scopeClass = scopeClass;
	}

	public List<DynaAttribute> getDynaAttributes() {
		return dynaAttributes;
	}

	public void setDynaAttributes(List<DynaAttribute> dynaAttributes) {
		this.dynaAttributes = dynaAttributes;
	}

	public String getTableAlias() {
		return tableAlias;
	}

	public void setTableAlias(String tableAlias) {
		this.tableAlias = tableAlias;
	}

	public Boolean getChecked() {
		return checked;
	}

	public void setChecked(Boolean checked) {
		this.checked = checked;
	}
	public List<MTMRelation> getMtmRelations() {
		return mtmRelations;
	}
	public void setMtmRelations(List<MTMRelation> mtmRelations) {
		this.mtmRelations = mtmRelations;
	}
    public Suit getSuit() {
        return suit;
    }
    public void setSuit(Suit suit) {
        this.suit = suit;
    }

}
